<template>
  <div class="component-b">
    <h2>{{ msg }}</h2>
    <!-- <p>当前最新的count值为:{{ count }}</p> -->
    <button @click="decrease(1)">+</button>
  </div>
</template>
<script>
// 1.从vuex中按需导入mapMutations函数
import { mapMutations } from "vuex";
export default {
  name: "componentB",
  data() {
    return {
      msg: "这里是B组件",
    };
  },
  computed: {
    count() {
      return this.$store.state.count;
    },
  },
  methods: {
    // 通过导入的mapMutations函数，将需要的mutations函数，映射为当前组件的methods方法
    ...mapMutations(["reduce"]),
    decrease(speed) {
      this.reduce(speed);
    },
  },
};
</script>
